home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 12
/
Mac Magazin and MacEasy Magazine CD - Issue 12.iso
/
Sharewarebibliothek
/
Anwendungen
/
Grafik
/
Matt's_Fract(Fat)101
/
Sources
/
fractal.c
next >
Wrap
C/C++ Source or Header
|
1995-07-10
|
27KB
|
1,336 lines
#include "AllTools.h"
#include "fractal.h"
#define NIL_POINTER 0L
#define REMOVE_ALL_EVENTS 0
#define mrBlob1 ((x >> 8) & 255) + (y & 65280)
#define mrBlob2 ((x >> 8) & 254) + (y & 65024)
#define mrBlob3 ((x >> 8) & 252) + (y & 64512)
#define heightShift 7
void Maketables(void);
void ToolBoxInit(void);
void WindowInit(void);
void MemInit(void);
void MemEnd(void);
void FillWindowBlack(WindowPtr theWindow);
void WindowMove(void);
void clearOffScreen(void);
void copyOffScreen(void);
void ToDrawX1(void);
void ToDrawX2(void);
void ToDrawX4(void);
void DoPreferences(void);
void MakeMap(void);
void ChangeHeight( int pss, int height );
void Smooth(int pss);
void MakeCols(void);
void BlurMap(void);
void Quit(void);
int hght(short x, short y);
int hght2(short x, short y);
void fixVars(void);
long myRnd(long range);
typedef struct
{
unsigned char map[256][256];
} MAP, *mapPeek;
typedef struct
{
unsigned long colorGrid[256][512];
} aCol, *aColPeek;
WindowPtr EliteWindow, theGameWindow;
Rect theGameRect;
PaletteHandle fracCols;
Ptr offScreen;
Ptr theTemp, theTemp2, theTemp3;
videoInfo theScreen;
Ptr ScrnBase;
long hhhh, xxxx,yyyy;;
long mapX, mapY, initPss, mapXp, mapYp;
long windX, windY, rayLen, xStep, yStep, windX2, windY2, windX4, windXstep, windYsteps, yOffSet;
long cs[2560], sn[2560], angle;
long theSize;
long rBts, xres2, yres2, orfset;
unsigned short mx, my;
long mx2, my2;
long randSeed, waterLevel;
Boolean shade, endIt;
unsigned long sky;
long velocity;
short pNum;
mapPeek the, the2;
aColPeek the3;
short oldBitDepth;
long tempHeight;
short RayLengthOption, PixelSizeOption, LandScapeOption, WindowSizeOption;
main()
{
MbarInit();
RayLengthOption = 1;
PixelSizeOption = 1;
LandScapeOption = 1;
WindowSizeOption = 1;
pNum = 2;
angle = 0;
mapX = 256;
mapY = 256;
initPss = 64;
windX = 256;
windY = 192;
rayLen = 511;
xStep = 4;
yStep = 2;
shade = TRUE;
randSeed= 2;
waterLevel= 0;
yOffSet = 64;
velocity = 256;
sky = (unsigned long)2;
sky = (sky | (sky << 8));
sky = (sky | (sky << 8));
sky = (sky | (sky << 8));
mapX = 256;
mapY = 256;
initPss = 64;
mapXp = mapX - 1;
mapYp = mapY - 1;
xxxx = 0;
yyyy = 0;
ToolBoxInit();
WindowInit();
MemInit();
Maketables();
fixVars();
endIt = TRUE;
HideMenuBar();
while(TRUE)
{
DoPreferences();
fixVars();
WindowMove();
MakeMap();
BlurMap();
MakeCols();
clearOffScreen();
hhhh = ((long)(the->map[(short)((yyyy >> 8) & 255)][(short)((xxxx >> 8) & 255)] + 16) << heightShift);
while(!Button())
{
mx = getCursorX();
mx2 = (long)mx;
my = getCursorY();
my2 = (long)my;
angle = angle - ((xres2 - mx2) >> 3);
if ( angle > 2559 ) angle = angle - 2560;
if ( angle < 0 ) angle = angle + 2560;
hhhh = hhhh - ((yres2 - my2));
yOffSet = ((yres2 - my2) >> 1);
if ((*(long*)(0x174)) == 1) velocity = velocity + 16;
if ((*(long*)(0x174)) == 8) velocity = velocity - 16;
xxxx = xxxx + ((cs[angle] * velocity) >> 8);
yyyy = yyyy + ((sn[angle] * velocity) >> 8);
tempHeight = ((long)(the->map[(short)((yyyy >> 8) & 255)][(short)((xxxx >> 8) & 255)] + 16) << heightShift);
if (hhhh < tempHeight) hhhh = tempHeight;
if (xStep == 1) ToDrawX1();
if (xStep == 2) ToDrawX2();
if (xStep == 4) ToDrawX4();
}
}
}
void fixVars(void)
{
angle = 0;
rBts = (long)(theScreen.rowBytes);
xres2 = (long)((theScreen.resolutionX) >> 1);
yres2 = (long)((theScreen.resolutionY) >> 1);
theSize = windX * windY;
orfset = (xres2 - windX) + ((yres2 - windY) * rBts);
windX2 = windX << 1;
windY2 = windY << 1;
windX4 = windX2 << 1;
windYsteps = windY2 / yStep;
windXstep = yStep * windX2;
velocity = 512;
}
void Maketables(void)
{
long cnt;
float num;
long colr, shady, depth;
long colorPtr;
long shaded, shaded2;
for (cnt = 0; cnt < 2560; cnt = cnt + 1)
{
num = (float)cnt * 0.00245436926062;
cs[cnt] = (long)(cos(num) * 256);
sn[cnt] = (long)(sin(num) * 256);
}
theTemp3 = NewPtr( 527364 );
if (theTemp3 == 0) ExitToShell();
the3 = (aColPeek)theTemp3;
for (colr = 0;colr < 16; colr++)
{
for (shady = 0;shady<16; shady++)
{
colorPtr = ((colr << 4) + shady);
for (depth = 0;depth < 512; depth ++)
{
shaded = ((shady << 2) - ((shady * depth) >> 7));
shaded2 = shaded & 1;
shaded = shaded >> 1;
shaded2 = shaded2 + shaded;
if (shaded2 > 31) shaded2 = 31;
shaded = (shaded + (colr * 32));
shaded2 = (shaded2 + (colr * 32));
shaded = shaded + (shaded2 << 8);
shaded = shaded + (shaded << 16);
the3->colorGrid[(short)colorPtr][(short)depth] = (unsigned long)shaded;
}
}
}
}
void ToolBoxInit(void)
{
InitGraf(&qd.thePort);
InitFonts();
FlushEvents(everyEvent, REMOVE_ALL_EVENTS);
InitWindows();
InitMenus();
TEInit();
InitDialogs(NIL_POINTER);
InitCursor();
theScreen = GetVideoInfo();
ScrnBase = theScreen.screenBase;
}
void WindowInit(void)
{
DialogPtr dialog;
Boolean itsDone;
short itemHit;
oldBitDepth = theScreen.bitsPerPixel;
if (theScreen.BitDepthPossible[8] == FALSE) DoError( 17, TRUE);
if ((theScreen.bitsPerPixel != 8) && (theScreen.BitDepthPossible[8] == TRUE))
{
SysBeep(1);
dialog = GetNewDialog(132, nil, (WindowPtr)-1);
CenterDialog(dialog, theScreen);
DrawDialog(dialog);
itsDone = FALSE;
FlushEvents(everyEvent, REMOVE_ALL_EVENTS);
while(!itsDone)
{
ModalDialog(nil, &itemHit);
if (itemHit == 1) {
ChangeBitDepth(8,1);
theScreen = GetVideoInfo();
itsDone = TRUE;
}
if (itemHit == 2) {
ExitToShell();
}
}
}
EliteWindow = NewCWindow( 0L, &theScreen.screenRect, "\pFractal", TRUE, plainDBox, ( WindowPtr ) -1, FALSE, 0L );
SelectWindow(EliteWindow);
SetPort(EliteWindow);
SetRect(&theGameRect, 0, 0, (windX << 1), (windY << 1));
theGameWindow = NewCWindow(nil, &theGameRect, "\pFractal", TRUE, 1, (WindowPtr)-1, FALSE, 0);
MoveWindow(theGameWindow, (theScreen.resolutionX >>1) - windX,
(theScreen.resolutionY >>1) - windY, FALSE);
FillWindowBlack(EliteWindow);
SetPort(theGameWindow);
SelectWindow(theGameWindow);
SelectWindow(theGameWindow);
FillWindowBlack(theGameWindow);
fracCols = GetNewPalette( (127+pNum) );
}
void WindowMove(void)
{
qd.randSeed = randSeed;
SelectWindow(EliteWindow);
SetPort(EliteWindow);
SetRect(&theGameRect, 0, 0, (windX << 1), (windY << 1));
SizeWindow(theGameWindow, (windX << 1), (windY << 1), TRUE);
MoveWindow(theGameWindow, (theScreen.resolutionX >>1) - windX,
(theScreen.resolutionY >>1) - windY, FALSE);
DisposePalette(fracCols);
fracCols = GetNewPalette( (127 + pNum) );
SetPalette( EliteWindow, fracCols, TRUE );
SetPalette( theGameWindow, fracCols, TRUE );
FillWindowBlack(EliteWindow);
FillWindowBlack(theGameWindow);
SetPort(theGameWindow);
SelectWindow(theGameWindow);
SelectWindow(theGameWindow);
}
void MemInit(void)
{
Size ScSize;
ScSize = (Size)(((long)640) * ((long)480));
theTemp = NewPtr( 66049);
if (theTemp == 0) DoError(6, TRUE);
theTemp2 = NewPtr( 66049);
if (theTemp2 == 0) DoError(6, TRUE);
offScreen = NewPtr( (long)ScSize );
if (offScreen == 0) DoError(6, TRUE);
the = (mapPeek)theTemp;
the2 = (mapPeek)theTemp2;
}
void MemEnd(void)
{
DisposPtr(theTemp);
DisposPtr(theTemp2);
DisposPtr(offScreen);
}
void FillWindowBlack(WindowPtr theWindow)
{
SetPort(EliteWindow);
ForeColor( blackColor );
PaintRect( &EliteWindow->portRect );
SetPort(theGameWindow);
ForeColor( blackColor );
PaintRect( &theGameWindow->portRect );
}
void MakeMap(void)
{
short pss,height;
short x,y;
DialogPtr dialog;
dialog = GetNewDialog(129, nil, (WindowPtr)-1);
CenterDialog(dialog, theScreen);
DrawDialog(dialog);
FillWindowBlack(EliteWindow);
qd.randSeed = randSeed;
pss = initPss;
height = 128;
for( y = 0; y < mapY; y++ )
{
for( x = 0; x < mapX; x++ )
{
the->map[x][y] = 0;
}
}
while(pss > 4)
{
ChangeHeight( pss, height );
Smooth(pss);
pss = pss >> 1;
height = height >> 1;
if (height == 0) height = 1;
}
while(pss > 1)
{
Smooth(pss);
pss = pss >> 1;
}
DisposDialog(dialog);
}
void ChangeHeight( int pss, int height )
{
long x,y;
unsigned char c;
for ( x = 0; x < mapX; x = x + pss )
{
for( y = 0; y < mapY; y = y + pss )
{
c = the->map[x][y] + (Random() / (32768 / height)) ;
the->map[x][y] = c;
}
}
}
void Smooth(int pss)
{
long dff;
short x,y;
long c;
long misc;
dff = pss>>1;
for ( x = 0; x < mapX; x = x + pss )
{
for( y = 0; y < mapY; y = y + pss )
{
misc = (long)((long)hght(x,y) + (long)hght(x + pss,y) + (long)hght(x + pss,y + pss) + (long)hght(x,y + pss));
the->map[x+dff][y+dff] = (unsigned char)(misc >> 2);
c = (hght(x,y) + hght(x+pss,y))>> 1;
the->map[x+dff][y] = c;
c = (hght(x,y) + hght(x,y+pss))>> 1;
the->map[x][y+dff] = c;
c = ((long)((hght(x+pss,y+pss) + hght(x+pss,y))))>>1;
the->map[x+pss][y+dff] = c;
c = (hght(x+pss,y+pss) + hght(x,y+pss))>>1;
the->map[x+dff][y+pss] = c;
}
}
}
int hght(short x, short y)
{
return (unsigned char)the->map[x & mapXp][y & mapYp];
}
int hght2(short x, short y)
{
return (unsigned char)the2->map[x & mapXp][y & mapYp];
}
void BlurMap(void)
{
long hht;
short x,y;
long min, max, range, mlt;
DialogPtr dialog;
dialog = GetNewDialog(130, nil, (WindowPtr)-1);
CenterDialog(dialog, theScreen);
DrawDialog(dialog);
FillWindowBlack(EliteWindow);
min = 255;
max = 0;
for(x = 0; x < mapX; x++)
{
for(y = 0; y < mapY; y++)
{
hht = the->map[x][y];
the2->map[x][y] = hht;
if (hht > max) max = hht;
if (hht < min) min = hht;
}
}
range = max - min;
mlt = 255/ range;
for(x = 0; x < mapX; x++)
{
for(y = 0; y < mapY; y++)
{
hht = the->map[x][y];
hht = hht - min;
hht = hht - waterLevel;
if (hht < 0) hht = 0;
the2->map[x][y] = hht;
}
}
for(x = 0; x < mapX; x++)
{
for(y = 0; y < mapY; y++)
{
hht = (long)(((long)hght2(x+6,y-4)) << 2) + (((long)hght2(x-4,y+8)) << 2) + ((long)(hght2(x,y)) << 3);
the->map[x][y] = (unsigned char)(hht >> 5);
}
}
DisposDialog(dialog);
}
long myRnd(long range)
{
return (Random() / 65536) * range;
}
void MakeCols(void)
{
short x, y, c, co;
DialogPtr dialog;
dialog = GetNewDialog(131, nil, (WindowPtr)-1);
CenterDialog(dialog, theScreen);
DrawDialog(dialog);
FillWindowBlack(EliteWindow);
for( y = 0; y < mapX; y++)
{
for( x = 0; x < mapY; x++)
{
c = (short)((unsigned char)the->map[x][y]);
co = c;
c = (short)( ((long)(c -
((unsigned char)the->map
[((short)(x + 3) & mapXp)]
[((short)(y + 3) & mapYp)])
)) << 2 );
c = (short)(((long)c) >> 3);
c = c + 7;
if (c > 15) c = 15;
if (c < 0) c = 0;
c = c + 32;
if (co == 0) c = 47;
if (co > 0) c = c + 16;
if (co > 16) c = c + 16;
if (co > 32) c = c + 16;
if (co > 48) c = c + 16;
the2->map[x][y] = (unsigned char)(c);
}
}
DisposDialog(dialog);
FillWindowBlack(EliteWindow);
}
void copyOffScreen(void)
{
Ptr ta0, ta1, ta2;
long td0, td1, td2, td3, td7;
ta0 = offScreen;
ta0 += windXstep;
ta0 -= windX2;
ta1 = ScrnBase;
ta1+= orfset;
td1 = windYsteps;
td0 = (windX >> 1);
td0 -= 1;
td1 -= 1;
td2 = td0;
td3 = rBts - windX2;
while(td1 >= 0)
{
td7 = yStep - 1;
while(td7 >= 0)
{
td0 = td2;
ta2 = ta0 + (4 * td2);
while(ta2 >= ta0)
{
*(unsigned long*)(ta1) = *(unsigned long*)(ta0);
ta0 += 4;
ta1 += 4;
}
ta0 -= windX2;
ta1 += td3;
td7 -= 1;
}
ta0 += windXstep;
td1 -= 1;
}
}
void clearOffScreen(void)
{
Ptr offScreenCounter;
Ptr theEndCounter;
unsigned long skyColour;
offScreenCounter = offScreen;
theEndCounter = offScreenCounter + (theSize << 2);
skyColour = sky;
while(theEndCounter != offScreenCounter)
{
*(unsigned long*)(offScreenCounter) = skyColour;
offScreenCounter +=4;
}
}
void ToDrawX1(void)
{
long xp, yp, xp2;
long L;
long x, y;
long xv, zv;
long z, yv;
Ptr offScreen2;
unsigned short MrBlobby;
long rayLenTmp;
long xOffSet, xOffSetdiv, xChng, yztemp, yOffSet2;
xp = -windX;
xp2 = 0;
xChng = -((xres2 - mx2) >> 2);
xOffSet = xp * xChng;
xOffSetdiv = xOffSet >> 8;
while (xp < windX)
{
x = xxxx;
y = yyyy;
z = hhhh + (xOffSet >> 8);
yp = -windY;
L = 1;
offScreen2 = offScreen + xp2 + (((windY2-1) * windX2));
xv = (long)(cs[angle] - ((xp * sn[angle]) >> 8) );
zv = (long)(sn[angle] + ((xp * cs[angle]) >> 8) );
yv = yp - yOffSet - (xOffSet >> 8);
yOffSet2 = - yOffSet - xOffSetdiv;
rayLenTmp = 128;
if (rayLen < rayLenTmp) rayLenTmp = rayLen;
MrBlobby = mrBlob1;
while (L<rayLenTmp)
{
if ( *(theTemp + MrBlobby ) > (z >> heightShift) )
{
*(unsigned char*)(offScreen2) =
*(unsigned char*)(theTemp3 + (((long)*(theTemp2 + MrBlobby)) << 11) + (L << 2));
offScreen2 -= windXstep;
yp += yStep;
yv += yStep;
z = hhhh + (yv * L);
if (yp >= windY) goto end1;
}
else
{
L++;
x += xv;
y += zv;
z += yv;
MrBlobby = mrBlob1;
}
}
yv = yv << 1;
xv = xv << 1;
zv = zv << 1;
rayLenTmp = 256;
if (rayLen < rayLenTmp) rayLenTmp = rayLen;
if (yp>=windY) L = rayLenTmp;
while (L<rayLenTmp)
{
if ( *(theTemp + MrBlobby ) > (z >> heightShift) )
{
*(unsigned short*)(offScreen2) =
*(unsigned short*)(theTemp3 + (((long)*(theTemp2 + MrBlobby)) << 11) + (L << 2));
offScreen2 -= windXstep;
yp += yStep;
yztemp = yp + yOffSet2;
yv = yztemp << 1;
z = hhhh + (yztemp * L);
if (yp>=windY) goto end1;
}
else
{
L += 2;
x += xv;
y += zv;
z += yv;
MrBlobby = mrBlob1;
}
}
yv = yv << 1;
xv = xv << 1;
zv = zv << 1;
rayLenTmp = rayLen;
if (yp>=windY) goto end1;
while (L<rayLenTmp)
{
if ( *(theTemp + MrBlobby ) > (z >> heightShift) )
{
*(unsigned short*)(offScreen2) =
*(unsigned short*)(theTemp3 + (((long)*(theTemp2 + MrBlobby)) << 11) + (L << 2));
offScreen2 -= windXstep;
yp += yStep;
yztemp = yp + yOffSet2;
yv = yztemp << 2;
z = hhhh + (yztemp * L);
if (yp>=windY) L = rayLenTmp;
}
else
{
L += 4;
x += xv;
y += zv;
z += yv;
MrBlobby = mrBlob1;
}
}
end1:
xp2 += 1;
xp += 1;
xOffSet += xChng;
xOffSetdiv = xOffSet >> 8;
}
copyOffScreen();
clearOffScreen();
}
void ToDrawX2(void)
{
long xp, yp, xp2;
long L;
long x, y;
long xv, zv;
long z, yv;
Ptr offScreen2;
unsigned short MrBlobby;
long rayLenTmp;
long xOffSet, xOffSetdiv, xChng, yztemp, yOffSet2;
xp = -windX;
xp2 = 0;
xChng = -((xres2 - mx2) >> 2);
xOffSet = xp * xChng;
xOffSetdiv = xOffSet >> 8;
xChng = xChng << 1;
while (xp < windX)
{
x = xxxx;
y = yyyy;
z = hhhh + (xOffSet >> 8);
yp = -windY;
L = 1;
offScreen2 = offScreen + xp2 + (((windY2-1) * windX2));
xv = (long)(cs[angle] - ((xp * sn[angle]) >> 8) );
zv = (long)(sn[angle] + ((xp * cs[angle]) >> 8) );
yv = yp - yOffSet - (xOffSet >> 8);
yOffSet2 = - yOffSet - xOffSetdiv;
rayLenTmp = 128;
if (rayLen < rayLenTmp) rayLenTmp = rayLen;
MrBlobby = mrBlob1;
while (L<rayLenTmp)
{
if ( *(theTemp + MrBlobby ) > (z >> heightShift) )
{
*(unsigned short*)(offScreen2) =
*(unsigned short*)(theTemp3 + (((long)*(theTemp2 + MrBlobby)) << 11) + (L << 2));
offScreen2 -= windXstep;
yp += yStep;
yv += yStep;
z = hhhh + (yv * L);
if (yp >= windY) goto end2;
}
else
{
L++;
x += xv;
y += zv;
z += yv;
MrBlobby = mrBlob1;
}
}
yv = yv << 1;
xv = xv << 1;
zv = zv << 1;
rayLenTmp = 256;
if (rayLen < rayLenTmp) rayLenTmp = rayLen;
if (yp>=windY) L = rayLenTmp;
while (L<rayLenTmp)
{
if ( *(theTemp + MrBlobby ) > (z >> heightShift) )
{
*(unsigned short*)(offScreen2) =
*(unsigned short*)(theTemp3 + (((long)*(theTemp2 + MrBlobby)) << 11) + (L << 2));
offScreen2 -= windXstep;
yp += yStep;
yztemp = yp + yOffSet2;
yv = yztemp << 1;
z = hhhh + (yztemp * L);
if (yp>=windY) goto end2;
}
else
{
L += 2;
x += xv;
y += zv;
z += yv;
MrBlobby = mrBlob1;
}
}
yv = yv << 1;
xv = xv << 1;
zv = zv << 1;
rayLenTmp = rayLen;
if (yp>=windY) goto end2;
while (L<rayLenTmp)
{
if ( *(theTemp + MrBlobby ) > (z >> heightShift) )
{
*(unsigned short*)(offScreen2) =
*(unsigned short*)(theTemp3 + (((long)*(theTemp2 + MrBlobby)) << 11) + (L << 2));
offScreen2 -= windXstep;
yp += yStep;
yztemp = yp + yOffSet2;
yv = yztemp << 2;
z = hhhh + (yztemp * L);
if (yp>=windY) L = rayLenTmp;
}
else
{
L += 4;
x += xv;
y += zv;
z += yv;
MrBlobby = mrBlob1;
}
}
end2:
xp2 += 2;
xp += 2;
xOffSet += xChng;
xOffSetdiv = xOffSet >> 8;
}
copyOffScreen();
clearOffScreen();
}
void ToDrawX4(void)
{
long xp, yp, xp2;
long L;
long x, y;
long xv, zv;
long z, yv, yvc;
Ptr offScreen2;
unsigned short MrBlobby;
long rayLenTmp;
long xOffSet, xOffSetdiv, xChng, yOffSet2;
xp = -windX;
xp2 = 0;
xChng = -((xres2 - mx2) >> 2);
xOffSet = xp * xChng;
xOffSetdiv = xOffSet >> 8;
xChng = xChng << 2;
while (xp < windX)
{
x = xxxx;
y = yyyy;
z = hhhh + (xOffSet >> 8);
yp = -windY;
L = 0;
offScreen2 = offScreen + xp2 + (((windY2-1) * windX2));
xv = (long)(cs[angle] - ((xp * sn[angle]) >> 8) );
zv = (long)(sn[angle] + ((xp * cs[angle]) >> 8) );
yvc = 0;
yv = yp - yOffSet - (xOffSet >> 8);
yOffSet2 = - yOffSet - xOffSetdiv;
rayLenTmp = 127;
if (rayLen < rayLenTmp) rayLenTmp = rayLen;
MrBlobby = mrBlob1;
loop41:
{
if ( *(theTemp + MrBlobby ) > (z >> heightShift) )
{
*(long*)(offScreen2) =
*(long*)(theTemp3 + (((long)*(theTemp2 + MrBlobby)) << 11) + (L << 2));
offScreen2 -= windXstep;
yp += yStep;
yv += yStep;
z += yvc;
if (yp >= windY) goto end43;
}
else
{
L++;
if (L >= rayLenTmp) goto end41;
z += yv;
x += xv;
y += zv;
yvc += yStep;
MrBlobby = mrBlob1;
}
}
goto loop41;
end41:
yv = yv << 1;
xv = xv << 1;
zv = zv << 1;
rayLenTmp = 255;
if (rayLen < rayLenTmp) rayLenTmp = rayLen;
loop42:
{
if ( *(theTemp + MrBlobby ) > (z >> heightShift) )
{
*(unsigned long*)(offScreen2) =
*(unsigned long*)(theTemp3 + (((long)*(theTemp2 + MrBlobby)) << 11) + (L << 2));
offScreen2 -= windXstep;
yp += yStep;
yv = (yp + yOffSet2) << 1;
z += yvc;
if (yp>=windY) goto end43;
}
else
{
L += 2;
if (L >= rayLenTmp) goto end42;
x += xv;
y += zv;
z += yv;
yvc += (yStep << 1);
MrBlobby = mrBlob2;
}
}
goto loop42;
end42:
yv = yv << 1;
xv = xv << 1;
zv = zv << 1;
rayLenTmp = rayLen;
loop43:
{
if ( *(theTemp + MrBlobby ) > (z >> heightShift) )
{
*(unsigned long*)(offScreen2) =
*(unsigned long*)(theTemp3 + (((long)*(theTemp2 + MrBlobby)) << 11) + (L << 2));
offScreen2 -= windXstep;
yp += yStep;
yv = (yp + yOffSet2) << 2;
z += yvc;
if (yp>=windY) goto end43;
}
else
{
L += 4;
if (L >= rayLenTmp) goto end43;
x += xv;
y += zv;
z += yv;
yvc += (yStep << 2);
MrBlobby = mrBlob3;
}
}
goto loop43;
end43:
xp2 += 4;
xp += 4;
xOffSet += xChng;
xOffSetdiv = xOffSet >> 8;
}
copyOffScreen();
clearOffScreen();
}
void DoPreferences(void)
{
Boolean itsDone;
DialogPtr theDialog, theDialog2;
short itemHit, itemHit2;
Rect iRect;
Point tempPoint;
Rect tempRect;
StringHandle string;
short WindowSizeError, WindowSizeTemp;
short PixelSizeError, PixelSizeTemp;
short LandScapeError, LandScapeTemp;
short RayLenError, RayLenTemp;
ControlHandle WindSizeCtrl, PixSizeCtrl, LandCtrl, RayLenCtrl;
MenuHandle WindSizeMenu, LandMenu, PixSizeMenu, RayLenMenu;
ShowCursor();
string = NewHandle(256);
theDialog = GetNewDialog(133, nil, EliteWindow);
if (theDialog == 0) DoError(4 ,TRUE);
SetPort(theDialog);
CenterDialog(theDialog, theScreen);
BringToFront(theDialog);
DrawDialog(theDialog);
tempRect = GetDRect(theDialog, mWindSize);
WindSizeCtrl = NewControl(theDialog, &tempRect, "", TRUE, 1, WindSizeMnu, 0, (1008 + 5), WindSizeMnu);
if (WindSizeCtrl == 0) DoError(18 ,TRUE);
WindSizeMenu = GetMenu(WindSizeMnu);
if (WindSizeMenu == 0) DoError(1 ,TRUE);
InsertMenu(WindSizeMenu, -1);
if (theScreen.resolutionX < 640) DisableItem(WindSizeMenu, 6);
if (theScreen.resolutionX < 640) DisableItem(WindSizeMenu, 5);
if (theScreen.resolutionX < 512) DisableItem(WindSizeMenu, 4);
if (theScreen.resolutionX < 400) DisableItem(WindSizeMenu, 3);
if (theScreen.resolutionX < 320) DisableItem(WindSizeMenu, 2);
if (theScreen.resolutionX < 160) DisableItem(WindSizeMenu, 1);
if (theScreen.resolutionY < 480) DisableItem(WindSizeMenu, 6);
if (theScreen.resolutionY < 400) DisableItem(WindSizeMenu, 5);
if (theScreen.resolutionY < 384) DisableItem(WindSizeMenu, 4);
if (theScreen.resolutionY < 300) DisableItem(WindSizeMenu, 3);
if (theScreen.resolutionY < 240) DisableItem(WindSizeMenu, 2);
if (theScreen.resolutionY < 120) DisableItem(WindSizeMenu, 1);
tempRect = GetDRect(theDialog, mPixelSize);
PixSizeCtrl = NewControl(theDialog, &tempRect, "", TRUE, 1, PixSizeMnu, 0, (1008 + 5), WindSizeMnu);
if (PixSizeCtrl == 0) DoError(18 ,TRUE);
PixSizeMenu = GetMenu(PixSizeMnu);
if (PixSizeMenu == 0) DoError(1 ,TRUE);
InsertMenu(PixSizeMenu, -1);
tempRect = GetDRect(theDialog, mLandscape);
LandCtrl = NewControl(theDialog, &tempRect, "", TRUE, 1, LandMnu, 0, (1008 + 5), WindSizeMnu);
if (LandCtrl == 0) DoError(18 ,TRUE);
LandMenu = GetMenu(LandMnu);
if (LandMenu == 0) DoError(1 ,TRUE);
InsertMenu(LandMenu, -1);
tempRect = GetDRect(theDialog, mRayLength);
RayLenCtrl = NewControl(theDialog, &tempRect, "", TRUE, 1, RayLenMnu, 0, (1008 + 5), WindSizeMnu);
if (RayLenCtrl == 0) DoError(18 ,TRUE);
RayLenMenu = GetMenu(RayLenMnu);
if (RayLenMenu == 0) DoError(1 ,TRUE);
InsertMenu(RayLenMenu, -1);
SetTheInfo(theDialog, tRandSeed, randSeed);
SetTheInfo(theDialog, tWaterLevel, waterLevel);
SetCtlValue(PixSizeCtrl, (short)PixelSizeOption);
SetCtlValue(WindSizeCtrl, (short)WindowSizeOption);
SetCtlValue(LandCtrl, (short)LandScapeOption);
SetCtlValue(RayLenCtrl, (short)RayLengthOption);
tempRect = GetDRect( theDialog, 18);
FrameRect(&tempRect);
itsDone = FALSE;
FlushEvents(everyEvent, REMOVE_ALL_EVENTS);
while(!itsDone)
{
ModalDialog(nil, &itemHit);
if (itemHit == bOK) {
itsDone = TRUE;
}
if (itemHit == bQuit) {
Quit();
}
if (itemHit == bAbout) {
FlushEvents(everyEvent, REMOVE_ALL_EVENTS);
theDialog2 = GetNewDialog(8000, nil, EliteWindow);
CenterDialog(theDialog2, theScreen);
BringToFront(theDialog2);
itemHit2 = 1;
while(itemHit2 != 2) { ModalDialog(nil, &itemHit2); }
DisposDialog(theDialog2);
FlushEvents(everyEvent, REMOVE_ALL_EVENTS);
tempRect = GetDRect( theDialog, 18);
FrameRect(&tempRect);
}
if (itemHit == bRandomize){
qd.randSeed = (unsigned long)TickCount();
randSeed = Random() + 32767;
if (randSeed == 0) randSeed = 1;
SetTheInfo(theDialog, tRandSeed, randSeed);
}
if (itemHit == mWindSize){
WindowSizeError = WindowSizeOption;
iRect = GetDRect(theDialog, mWindSize);
tempPoint.v = iRect.top;
tempPoint.h = iRect.left;
LocalToGlobal(&tempPoint);
WindowSizeTemp = PopUpMenuSelect(WindSizeMenu, tempPoint.v, tempPoint.h, WindowSizeOption);
if (WindowSizeTemp != 0) WindowSizeOption = WindowSizeTemp;
SetCtlValue(WindSizeCtrl, (short)WindowSizeOption);
}
if (itemHit == mPixelSize){
PixelSizeError = PixelSizeOption;
iRect = GetDRect(theDialog, mPixelSize);
tempPoint.v = iRect.top;
tempPoint.h = iRect.left;
LocalToGlobal(&tempPoint);
PixelSizeTemp = PopUpMenuSelect(PixSizeMenu, tempPoint.v, tempPoint.h, PixelSizeOption);
if (PixelSizeTemp != 0) PixelSizeOption = PixelSizeTemp;
SetCtlValue(PixSizeCtrl, (short)PixelSizeOption);
}
if (itemHit == mLandscape){
LandScapeError = LandScapeOption;
iRect = GetDRect(theDialog, mLandscape);
tempPoint.v = iRect.top;
tempPoint.h = iRect.left;
LocalToGlobal(&tempPoint);
LandScapeTemp = PopUpMenuSelect(LandMenu, tempPoint.v, tempPoint.h, LandScapeOption);
if (LandScapeTemp != 0) LandScapeOption = LandScapeTemp;
SetCtlValue(LandCtrl, (short)LandScapeOption);
}
if (itemHit == mRayLength){
RayLenError = RayLengthOption;
iRect = GetDRect(theDialog, mRayLength);
tempPoint.v = iRect.top;
tempPoint.h = iRect.left;
LocalToGlobal(&tempPoint);
RayLenTemp = PopUpMenuSelect(RayLenMenu, tempPoint.v, tempPoint.h, RayLengthOption);
if (RayLenTemp != 0) RayLengthOption = RayLenTemp;
SetCtlValue(RayLenCtrl, (short)RayLengthOption);
}
}
GetTheInfoStr(theDialog, tRandSeed, string);
StringToNum(*string, &randSeed);
GetTheInfoStr(theDialog, tWaterLevel, string);
StringToNum(*string, &waterLevel);
if (randSeed == 0) randSeed = 1;
tempPoint.v = 0;
tempPoint.h = 0;
ShieldCursor(&theScreen.screenRect, tempPoint);
DisposHandle(string);
switch (WindowSizeOption) {
case 1: { windX = 80;
windY = 60;
} break;
case 2: { windX = 160;
windY = 120;
} break;
case 3: { windX = 200;
windY = 150;
} break;
case 4: { windX = 256;
windY = 192;
} break;
case 5: { windX = 320;
windY = 200;
} break;
case 6: { windX = 320;
windY = 240;
} break;
}
switch (PixelSizeOption) {
case 1: { xStep = 1;
yStep = 1;
} break;
case 2: { xStep = 2;
yStep = 1;
} break;
case 3: { xStep = 2;
yStep = 2;
} break;
case 4: { xStep = 4;
yStep = 2;
} break;
case 5: { xStep = 4;
yStep = 4;
} break;
}
switch (RayLengthOption) {
case 1: { rayLen = 128;
} break;
case 2: { rayLen = 200;
} break;
case 3: { rayLen = 256;
} break;
case 4: { rayLen = 320;
} break;
case 5: { rayLen = 400;
} break;
case 6: { rayLen = 512;
} break;
}
pNum = LandScapeOption;
}
void Quit(void)
{
ShowCursor();
ShowMenuBar();
MemEnd();
FlushEvents(everyEvent, REMOVE_ALL_EVENTS);
ChangeBitDepth(oldBitDepth,1);
ExitToShell();
}